package resoft.jeasyform.components;

import resoft.jeasyform.event.EventHandler;
import resoft.jeasyform.event.DefaultEventHandler;
import resoft.jeasyform.event.InputFieldEventAware;

import java.util.Collection;
import java.util.ArrayList;

/**
 * <p></p>
 * User: albert
 * Date: Aug 28, 2007
 * Time: 12:46:29 AM
 */
public abstract class InputField extends Component implements InputFieldEventAware ,AcceptFocusAware {

    protected InputField() {
        setAcceptFocus(true);
    }

    public abstract String getValue();

    public abstract void setValue(String value);


    public int getMaxLength() {
        return maxLength;
    }

    public void setMaxLength(int maxLength) {
        this.maxLength = maxLength;
    }

    /**
     * register pre event
     * @param preHandler EventHandler
     * */
    public void registerPreEvent(EventHandler preHandler) {
        this.preHandler = preHandler;
    }

    /**
     * register post event
     * @param postHandler EventHandler
     * */
    public void registerPostEvent(EventHandler postHandler) {
        if(postHandler!=null) {
            postEventChain.add(postHandler);
        }
    }

    /**
     * get preEvent
     *
     * @return EventHandler
     * */
    protected EventHandler getPreEvent() {
        return this.preHandler;
    }

    /**
     * get postEvent chain
     *
     * @return Collection event chain
     * */
    protected Collection getPostEventChain() {
        return postEventChain;
    }

    public abstract charva.awt.Component getSwingObject();

    private int maxLength = 0;

    public abstract void requestFocus();

    private EventHandler preHandler = new DefaultEventHandler();

    private Collection postEventChain = new ArrayList();    
}
